package dS.ProjectGPS.LeicaOWI;

import javax.microedition.lcdui.*;

public class FormOwiDPM extends Form implements FormOwi {

  OWIAgent owiAgent = null;

  ChoiceGroup interf = new ChoiceGroup("Interface", ChoiceGroup.POPUP);
  TextField deviceName = new TextField("Device Name", "", 30, TextField.ANY);
  ChoiceGroup assignToPort = new ChoiceGroup("Assign To Port",
                                             ChoiceGroup.EXCLUSIVE);

  public FormOwiDPM(OWIAgent o) {
    super("Device Port Manager");

    owiAgent = o;

    try {
      ndsInit();
    }
    catch (Exception ex) {
    }
  }

  public void ndsInit() throws Exception {
    append(interf);
    interf.append("Hidden Point", null);
    interf.append("Realtime 1", null);
    interf.append("Realtime 2", null);
    interf.append("NMEA Message", null);
    interf.append("Notify Event", null);
    interf.append("Notify PPS", null);
    interf.append("Remote Control", null);
    interf.append("ASCII Input", null);
    interf.append("Meteo", null);
    interf.append("Tilt", null);
    interf.append("GSI User Output", null);
    interf.append("ASCII Remote", null);
    append(deviceName);
    append(assignToPort);
    assignToPort.append("Device at Port 1", null);
    assignToPort.append("Device at Port 2", null);
    assignToPort.append("Device at Port 3", null);
  }

  public void update() {
    owiAgent.query(OWI.qsAHT(OWI.location));

    for(int i = 0; i<OWI.dpmNumDevices; i++){
      interf.setSelectedIndex(Integer.parseInt(OWI.dpmInterface), true);
      deviceName.setString((String)OWI.dpmDeviceName.elementAt(i));
      assignToPort.setSelectedIndex(OWI.type, true);
    }
  }

  public void save() {
/*    String msgId = "DPM";

    // Setup SET parameters
    String[] outputs = {msgId,
                       msgId[interf.getSelectedIndex()].getString(),
                       "" + type.getSelectedIndex()
    };

    //Send message and update form if successful
    int ackCode = (owiAgent.set(msgId, OWI.setMessage(outputs)));
    Controller.showACKAlert(this,this,ackCode);
*/
  }

}
